﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Common.BaseClasses;
using PostSharp.Aspects;
using PostSharp.Extensibility;

//using PostSharp.Aspects;
//using System.ComponentModel;
//using PostSharp.Extensibility;

namespace Common.Aspects
{
    [MulticastAttributeUsage(MulticastTargets.Property, Inheritance = MulticastInheritance.Multicast)]
    [Serializable]
    public class NotifyPropertyChangedAspect : LocationInterceptionAspect
    {
        public override void OnSetValue(LocationInterceptionArgs args)
        {
            base.OnSetValue(args);
            var model = args.Instance as ModelBase;
            if (model == null)
                return;
            var currentValue = args.GetCurrentValue();
            if (currentValue == args.Value)
                return;
            model.OnPropertyChanged(args.LocationName);
        }

    }
}
